package com.zqh.myfmmall.handler;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.zqh.myfmmall.result.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * @Description :
 * @Author :kono淇杭哒、
 * @Create 2021-08-27 22:28
 */
@Slf4j
@ControllerAdvice
public class GlobalExceptionHandler{

    @ExceptionHandler(value = RuntimeException.class)
    @ResponseBody
    public Result handler(RuntimeException e) {
        log.info("运行时异常" + e);
        return Result.fail("服务器错误");
    }

    @ExceptionHandler(value = JsonProcessingException.class)
    @ResponseBody
    public Result handler(JsonProcessingException e) {
        log.info("josn转换异常" + e);
        return Result.fail("服务器错误");
    }

    @ExceptionHandler(value = IOException.class)
    @ResponseBody
    public Result handler(IOException e) {
        log.info("io异常" + e);
        return Result.fail("服务器错误");
    }


}
